<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>vim必会命令 | 奉孝的测开日记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  
  
    <link rel="alternate" href="/blog/atom.xml" title="奉孝的测开日记" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
    
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/blog/localshare/css/share.css">

  
  
  
<meta name="generator" content="Hexo 5.4.2"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">奉孝的测开日记</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/blog/" id="subtitle">开启自我改变的原动力</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        
          <a class="main-nav-link" href="/blog/."><i class="fa fa-home"></i> 首页</a>
        
          <a class="main-nav-link" href="/blog/archives/"><i class="fa fa-archive"></i> 归档</a>
        
          <a class="main-nav-link" href="/blog/about/"><i class="fa fa-user"></i> 关于</a>
        
      </nav>
    </div>
    <div id="search-form">
      <div id="result-mask" class="hide"></div>
      <label><input id="search-key" type="text" autocomplete="off" placeholder="搜索"></label>
      <div id="result-wrap" class="hide">
        <div id="search-result"></div>
      </div>
      <div class="hide">
        <template id="search-tpl">
          <div class="item">
            <a href="/{path}" title="{title}">
              <div class="title">{title}</div>
              <div class="time">{date}</div>
              <div class="tags">{tags}</div>
            </a>
          </div>
        </template>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-vim必会命令" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      vim必会命令
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-10-17T07:52:00.000Z" itemprop="datePublished">2022年10月17日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/vim/">vim</a>
  </div>

      
        <span class="article-views">
  <i class="fa fa-views"></i>
  <i id="busuanzi_container_page_pv">
      <i id="busuanzi_value_page_pv"></i>
  </i>
</span>

      
      
<a href="/blog/2022/10/17/vim%E5%BF%85%E4%BC%9A%E5%91%BD%E4%BB%A4/#comments" class="article-comment-link">
  
    
    
    
    
    
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="中文文档"><a href="#中文文档" class="headerlink" title="中文文档"></a>中文文档</h1><p>以mac环境为例  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">cd ~/.vim // 如果没有文件夹就自己创建一个</span><br><span class="line">mkdir -p pack/my/start</span><br><span class="line">git clone https://github.com/yianwillis/vimcdoc.git pack/my/start/vimcdoc</span><br><span class="line">```  </span><br><span class="line">Vim 教程支持多语言，可使用命令 vimtutor 来启动。如果启动的教程的语言不是你希望的，</span><br><span class="line">你可以使用环境变量 LANG 来设定希望的语言   </span><br><span class="line">```shell</span><br><span class="line">LANG=zh_CN.UTF-8 vimtutor</span><br></pre></td></tr></table></figure>

<h1 id="基础命令"><a href="#基础命令" class="headerlink" title="基础命令"></a>基础命令</h1><h2 id="移动"><a href="#移动" class="headerlink" title="移动"></a>移动</h2><ul>
<li>h 左</li>
<li>l 右</li>
<li>j 下</li>
<li>k 上</li>
<li>w 从关标处移动至下一个单词的起始处</li>
<li>2w 移动2个单词</li>
<li>e 从关标处移动至该单词的末尾</li>
<li>3e 使光标向前移动到第三个单词的末尾</li>
<li>0 移动光标到行首</li>
<li>$ 移动光标到行尾</li>
<li>( 和 ) 移到上一句和下一句</li>
<li>{ 和 } 移到上一段和下一段</li>
<li>control-f  向下翻页</li>
<li>control-b  向上翻页</li>
<li>control-d  向下翻半页</li>
<li>control-u  向上翻半页</li>
<li>control-e   光标不动，向上滚动屏幕</li>
<li>control-y   光标不动，向下滚动屏幕</li>
<li>zt  鼠标所在当前行滚到屏幕顶部</li>
<li>zz  鼠标所在当前行滚到屏幕中部</li>
<li>zb  鼠标所在当前行滚到屏幕底部</li>
</ul>
<h2 id="替换"><a href="#替换" class="headerlink" title="替换"></a>替换</h2><ul>
<li>S 替换行</li>
<li>s 替换字符</li>
<li>r 输入 r 和一个字符替换光标所在位置的字符</li>
<li>R 可连续替换多个字符, R 将进入替换模式，直至按 <ESC> 键回到正常模式</li>
<li>:s/old/new  可以替换old为new,只改变光标所在行的第一个匹配串</li>
<li>:s/old/new/g  可以替换old为new,替换全行的匹配串</li>
<li>:%s/old/new/g  替换整个文件中的每个匹配串</li>
<li>:%s/old/new/gc 会找到整个文件中的每个匹配串，并且对每个匹配串提示是否进行替换</li>
<li>:#,#s/old/new/g 替换两行之间出现的每个匹配串，#,#代表行号</li>
</ul>
<h2 id="添加"><a href="#添加" class="headerlink" title="添加"></a>添加</h2><ul>
<li>A 在一行后添加文本</li>
<li>a 光标字符后添加文本</li>
<li>i 光标字符前添加文本</li>
<li>o  在光标 <strong>下方</strong> 打开新的一行，这个命令会使您进入插入模式</li>
<li>O  在光标 <strong>上方</strong> 打开新的一行，这个命令会使您进入插入模式</li>
</ul>
<h2 id="删除"><a href="#删除" class="headerlink" title="删除"></a>删除</h2><ul>
<li>D 当前行，删除光标以及光标后的</li>
<li>dd 删除当前行</li>
<li>d2d 从当前行开始，删除2行</li>
<li>dw 从关标处删除至下一个单词的起始处</li>
<li>d2w 删除2个单词</li>
<li>de 从关标处删除至单词末尾</li>
<li>d$ 从当前关标删除到行末</li>
<li>x 删除当前字符</li>
<li>X 删除关标所在位置的前一个字符<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">if (message == &quot;sesame open&quot;)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">假设关标在sesame的a上</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">dw（理解为 delete word） 删除<span class="string">&#x27;ame␣&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">diw（理解为 delete inside word） 删除<span class="string">&#x27;sesame&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">daw（理解为 delete a word） 删除<span class="string">&#x27;sesame␣&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">diW 会删除<span class="string">&#x27;&quot;sesame&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">daW 会删除<span class="string">&#x27;&quot;sesame␣&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">di<span class="string">&quot; 会删除&#x27;sesame open&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="string">da&quot;</span> 会删除<span class="string">&#x27;&quot;sesame open&quot;&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">di( 或 di) 会删除<span class="string">&#x27;message == &quot;sesame open&quot;&#x27;</span></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">da( 或 da) 会删除<span class="string">&#x27;(message == &quot;sesame open&quot;)&#x27;</span></span></span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="跳转定位"><a href="#跳转定位" class="headerlink" title="跳转定位"></a>跳转定位</h2><ul>
<li>G 跳转到结尾</li>
<li>gg 跳转到开头</li>
<li>ctrl-g   显示当前编辑文件中当前光标所在行位置以及文件状态信息</li>
<li>5G 定位到第5行</li>
<li>5| 定位到第5列</li>
<li>vim -c ‘normal 5G5|’ text.txt   直接定位到第5行第5列</li>
</ul>
<h2 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h2><ul>
<li>C 则相当于 c$，删除到行尾然后进入插入模式。</li>
<li>c 加动作来进行修改（cc 修改整行）</li>
</ul>
<h2 id="选择"><a href="#选择" class="headerlink" title="选择"></a>选择</h2><ul>
<li>V 选择行</li>
<li>v 选择字符</li>
</ul>
<h2 id="撤销"><a href="#撤销" class="headerlink" title="撤销"></a>撤销</h2><ul>
<li>u 撤销最后执行的命令</li>
<li>U 撤消在最后一行中所做的改动</li>
<li>ctrl-r(先按下ctrl键，接着按r键) 撤消掉撤消命令</li>
</ul>
<h2 id="复制"><a href="#复制" class="headerlink" title="复制"></a>复制</h2><ul>
<li>使用操作符 y 复制文本，使用 p 粘贴文本(v选中，y复制，p粘贴)</li>
<li>y 当作操作符来使用。例如:yw 可以用来复制一个单词</li>
</ul>
<h2 id="粘贴"><a href="#粘贴" class="headerlink" title="粘贴"></a>粘贴</h2><ul>
<li>p 最后一次删除的内容置入光标所在行的下一行(比如：先dd，然后输入p，粘贴)</li>
</ul>
<h2 id="修改-1"><a href="#修改-1" class="headerlink" title="修改"></a>修改</h2><ul>
<li>ce 改变文本直到一个单词的末尾</li>
</ul>
<h2 id="搜索"><a href="#搜索" class="headerlink" title="搜索"></a>搜索</h2><ul>
<li>/  输入 / 加上一个字符串可以用以在当前文件中查找该字符串</li>
<li>n 向下寻找</li>
<li>N 向上寻找</li>
<li>?代替/ 逆向查找，这样n就是向上寻找</li>
<li>ctrl-o 回退到之前的位置</li>
<li>ctrl-i 回到较新的位置</li>
<li>% 可以查找配对的括号 )、]、}  比如光标放在(，然后按%<h3 id="忽略大小写查找"><a href="#忽略大小写查找" class="headerlink" title="忽略大小写查找"></a>忽略大小写查找</h3></li>
<li>:set ic   Ignore Case，忽略大小写</li>
<li>:set hls is <ul>
<li>‘ic’ ‘ignorecase’       查找时忽略字母大小写</li>
<li>‘is’ ‘incsearch’        查找短语时显示部分匹配</li>
<li>‘hls’ ‘hlsearch’        高亮显示所有的匹配短语</li>
</ul>
</li>
<li>在选项前加上 no 可以关闭选项   比如  :set noic  禁用忽略大小写</li>
</ul>
<h2 id="在vim内执行外部命令"><a href="#在vim内执行外部命令" class="headerlink" title="在vim内执行外部命令"></a>在vim内执行外部命令</h2><ul>
<li>:!然后紧接着输入一个外部命领，比如:!ls -la</li>
</ul>
<h2 id="保存文件"><a href="#保存文件" class="headerlink" title="保存文件"></a>保存文件</h2><ul>
<li>:w FILENAME  将对文件的改动保存到新文件中，以 FILENAMEj 为文件名保存整个文件</li>
<li>选择性保存 先按V，上下移动，选中，然后按:  再输入w FILENAME</li>
</ul>
<h2 id="提取和合并文件"><a href="#提取和合并文件" class="headerlink" title="提取和合并文件"></a>提取和合并文件</h2><ul>
<li>光标放置待插入位置，输入: FILENAME(这是文件名)，就会把FILENAME中的内容提取到光标处</li>
<li>提取外部命令的输出。比如：:r !ls 可以读取 ls 命令的输出，并把它放置在光标下面</li>
</ul>
<h2 id="打开新的一行输入"><a href="#打开新的一行输入" class="headerlink" title="打开新的一行输入"></a>打开新的一行输入</h2><ul>
<li>o  在光标 <strong>下方</strong> 打开新的一行，这个命令会使您进入插入模式</li>
<li>O  在光标 <strong>上方</strong> 打开新的一行，这个命令会使您进入插入模式</li>
</ul>
<h2 id="命令补全"><a href="#命令补全" class="headerlink" title="命令补全"></a>命令补全</h2><ul>
<li>使用 CTRL-D 和 <TAB> 可以进行命令行补全。 当输入 : 命令时，按 CTRL-D 可以查看可能的补全结果</li>
</ul>
<h1 id="vimrc进阶配置"><a href="#vimrc进阶配置" class="headerlink" title=".vimrc进阶配置"></a>.vimrc进阶配置</h1><h2 id="基本配置"><a href="#基本配置" class="headerlink" title="基本配置"></a>基本配置</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">set enc=utf-8</span><br><span class="line">set nocompatible  # 关闭 vi 兼容模式</span><br><span class="line">source $VIMRUNTIME/vimrc_example.vim</span><br></pre></td></tr></table></figure>

<h2 id="备份和撤消文件"><a href="#备份和撤消文件" class="headerlink" title="备份和撤消文件"></a>备份和撤消文件</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">set nobackup</span><br><span class="line"></span><br><span class="line">if has(&#x27;persistent_undo&#x27;)</span><br><span class="line">  set undofile</span><br><span class="line">  set undodir=~/.vim/undodir</span><br><span class="line">  if !isdirectory(&amp;undodir)</span><br><span class="line">    call mkdir(&amp;undodir, &#x27;p&#x27;, 0700)</span><br><span class="line">  endif</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>

<h2 id="鼠标支持"><a href="#鼠标支持" class="headerlink" title="鼠标支持"></a>鼠标支持</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">if has(&#x27;mouse&#x27;)</span><br><span class="line">  if has(&#x27;gui_running&#x27;) || (&amp;term =~ &#x27;xterm&#x27; &amp;&amp; !has(&#x27;mac&#x27;))</span><br><span class="line">    set mouse=a</span><br><span class="line">  else</span><br><span class="line">    set mouse=nvi</span><br><span class="line">  endif</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>

<h2 id="中文支持"><a href="#中文支持" class="headerlink" title="中文支持"></a>中文支持</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">set fileencodings=ucs-bom,utf-8,gb18030,latin1</span><br></pre></td></tr></table></figure>

<h2 id="字体配置"><a href="#字体配置" class="headerlink" title="字体配置"></a>字体配置</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">if has(&#x27;gui_running&#x27;)</span><br><span class="line">  set guifont=Courier_New:h11:cANSI</span><br><span class="line">  set guifontwide=新宋体:h11:cGB2312</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>

<h2 id="只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行"><a href="#只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行" class="headerlink" title="只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行"></a>只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="built_in">set</span> scrolloff=5 会导致只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行</span></span><br><span class="line">set scrolloff=1 # 可以减少干扰</span><br></pre></td></tr></table></figure>
<p>:</p>
<h2 id="minpac安装"><a href="#minpac安装" class="headerlink" title="minpac安装"></a>minpac安装</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone https://github.com/k-takata/minpac.git ~/.vim/pack/minpac/opt/minpac</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">if exists(&#x27;*minpac#init&#x27;)</span><br><span class="line"><span class="meta prompt_">  # </span><span class="language-bash">Minpac is loaded.</span></span><br><span class="line">  call minpac#init()</span><br><span class="line">  call minpac#add(&#x27;k-takata/minpac&#x27;, &#123;&#x27;type&#x27;: &#x27;opt&#x27;&#125;)</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_">  # </span><span class="language-bash">Other plugins</span></span><br><span class="line">endif</span><br><span class="line"></span><br><span class="line">if has(&#x27;eval&#x27;)</span><br><span class="line"><span class="meta prompt_">  # </span><span class="language-bash">Minpac commands</span></span><br><span class="line">  command! PackUpdate packadd minpac | source $MYVIMRC | call minpac#update(&#x27;&#x27;, &#123;&#x27;do&#x27;: &#x27;call minpac#status()&#x27;&#125;)</span><br><span class="line">  command! PackClean  packadd minpac | source $MYVIMRC | call minpac#clean()</span><br><span class="line">  command! PackStatus packadd minpac | source $MYVIMRC | call minpac#status()</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>

<h2 id="最近使用的文件"><a href="#最近使用的文件" class="headerlink" title="最近使用的文件"></a>最近使用的文件</h2><p>安装插件，然后执行:PackUpdate    </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">Other plugins</span></span><br><span class="line">call minpac#add(&#x27;yegappan/mru&#x27;)</span><br></pre></td></tr></table></figure>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">if !has(&#x27;gui_running&#x27;)</span><br><span class="line">  &quot; 设置文本菜单</span><br><span class="line">  if has(&#x27;wildmenu&#x27;)</span><br><span class="line">    set wildmenu</span><br><span class="line">    set cpoptions-=&lt;</span><br><span class="line">    set wildcharm=&lt;C-Z&gt;</span><br><span class="line">    nnoremap &lt;F10&gt;      :emenu &lt;C-Z&gt;</span><br><span class="line">    inoremap &lt;F10&gt; &lt;C-O&gt;:emenu &lt;C-Z&gt;</span><br><span class="line">  endif</span><br><span class="line">endif</span><br></pre></td></tr></table></figure>
<p>输入 :emenu  再按tab就可以看到最近打开的文件</p>
<h2 id="已经存在交换文件"><a href="#已经存在交换文件" class="headerlink" title="已经存在交换文件"></a>已经存在交换文件</h2><p>错误提示<code>Swap file &quot;Desktop/logs/.text.txt.swp&quot; already exists!</code>，有两种原因：  </p>
<ol>
<li>上次编辑这个文件时，发生了意外崩溃</li>
<li>已经在使用另外一个vim会话编辑这个文件了<br>错误提示 process ID 后面没有”STILL RUNNING”这样的字样，就是情况1，其他就是情况2<br>针对情况1，可以<code>vim -r text.txt</code>恢复上次的编辑状态，确认之后，根据提示，删除交换文件。  </li>
</ol>
<h2 id="多文件打开的方式"><a href="#多文件打开的方式" class="headerlink" title="多文件打开的方式"></a>多文件打开的方式</h2><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">vim *.txt *.log  # 暂时只打开第一个文件</span><br><span class="line"></span><br><span class="line">:args  要编辑的多文件列表</span><br><span class="line">:args *.xml  使用xml文件替换参数列表</span><br><span class="line">:next(:n)  打开下一个文件</span><br><span class="line">:Next(:N)或者:previous(:prev)  打开上一个文件</span><br><span class="line">:first  回到列表中的第一个文件</span><br><span class="line">:last   打开列表中的最后一个文件</span><br><span class="line"></span><br><span class="line">工作流：</span><br><span class="line">:set autowrite  告诉vim在切换文件时自动存盘</span><br><span class="line">:n|normal ggP   切换到下一个文件并执行正常模式命令ggP,跳转到文件开头并粘贴</span><br><span class="line">:向上箭头  执行上面的命令</span><br><span class="line"></span><br><span class="line">缓冲区：</span><br><span class="line">:ls  查看缓冲区列表（当前活跃%a  最近的缓冲区#  缓冲区已被修改+）</span><br><span class="line">:buffer(:b) 编号  跳转到编号对应的缓冲区。比如:b3  如果当前缓冲区已被修改但为保存，会报错，命令后加!会放弃修改，比如b!2 </span><br><span class="line">:bdelete(:bd) 编号  删除对应的缓冲区。:bd 8</span><br><span class="line">:bnext(:bn)  下一个</span><br><span class="line">:bprevious(:bp) 上一个</span><br><span class="line">:blast  最后一个</span><br><span class="line"></span><br><span class="line">control ^  最近的两个缓冲区之间来回切换</span><br></pre></td></tr></table></figure>

<h2 id="多窗口编辑"><a href="#多窗口编辑" class="headerlink" title="多窗口编辑"></a>多窗口编辑</h2><ul>
<li>水平分割<ul>
<li>:split(:sp) 当前窗口分隔开，当前编辑的文件在两个窗口里都显示</li>
<li>:split(:sp) 文件名 分割窗口并打开该文件</li>
</ul>
</li>
<li>竖直分割<ul>
<li>:vsplit(:vs)<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">control w w 跳转下一个窗口</span><br><span class="line">:new 或 control w n  打开新窗口</span><br><span class="line">:close 或 control w c 关闭当前窗口，最后一个无效</span><br><span class="line">:quit 或 control w q 退出当前窗口，最后一个则退出vim</span><br><span class="line">:only 或 control w o  只保留当前</span><br><span class="line">control w =   所有窗口大小相等</span><br><span class="line">control w 10_  设置高度为10</span><br><span class="line">control w 10|  设置宽度为10</span><br><span class="line">control w +  增加窗口高度，默认1</span><br><span class="line">control w -  减少窗口高度</span><br><span class="line">control w &gt;  增加窗口宽度</span><br></pre></td></tr></table></figure>
<h3 id="双窗口比较"><a href="#双窗口比较" class="headerlink" title="双窗口比较"></a>双窗口比较</h3></li>
</ul>
</li>
<li>vimdiff .vimrc ~/.vimrc</li>
</ul>
<h3 id="多标签页"><a href="#多标签页" class="headerlink" title="多标签页"></a>多标签页</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">:tabs  展示标签列表</span><br><span class="line">:tabnew 或 :tabedit 打开新的标签页。后跟文件名，新的标签打开这个文件</span><br><span class="line">:tabclose  关闭当前标签</span><br><span class="line">:tabnext 下一个标签页</span><br><span class="line">:tabprevious</span><br><span class="line">:tabfirst</span><br><span class="line">:tablast</span><br><span class="line">:control-w T 当前窗口变成一个新标签页</span><br></pre></td></tr></table></figure>

<h3 id="NERDTree插件"><a href="#NERDTree插件" class="headerlink" title="NERDTree插件"></a>NERDTree插件</h3><h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><p>.vimrc文件中增加  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">call minpac#add(&#x27;preservim/nerdtree&#x27;)</span><br></pre></td></tr></table></figure>
<p>然后执行<code>PackUpdate</code>,如果一直失败，也可以直接克隆<code>git clone https://github.com/preservim/nerdtree.git ~/.vim/pack/minpac/start/nerdtree</code>  </p>
<h4 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h4><ul>
<li>NERDTreeToggle  左侧打开文件浏览/管理窗口，也可以关闭</li>
<li>go  浏览文件，光标不会跳转到文件所在窗口</li>
<li>i   打开文件到新的水平分割窗口</li>
<li>s   打开文件到新的竖直分割窗口 </li>
<li>t   打开文件到新的标签页</li>
<li>m   出现菜单，可以添加、删除、更名</li>
<li>?  查看帮助信息</li>
</ul>
<h2 id="正则表达式：实现文件内容的搜索和替换"><a href="#正则表达式：实现文件内容的搜索和替换" class="headerlink" title="正则表达式：实现文件内容的搜索和替换"></a>正则表达式：实现文件内容的搜索和替换</h2>
        
            <div id="toc-article">
                
  <div class="widget-wrap" id="toc-wrap">
    <h3 class="widget-title"><i class="fa fa-toc"></i> 文章目录</h3>
    <div class="widget">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%AD%E6%96%87%E6%96%87%E6%A1%A3"><span class="toc-text">中文文档</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9F%BA%E7%A1%80%E5%91%BD%E4%BB%A4"><span class="toc-text">基础命令</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%A7%BB%E5%8A%A8"><span class="toc-text">移动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9B%BF%E6%8D%A2"><span class="toc-text">替换</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B7%BB%E5%8A%A0"><span class="toc-text">添加</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%A0%E9%99%A4"><span class="toc-text">删除</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B7%B3%E8%BD%AC%E5%AE%9A%E4%BD%8D"><span class="toc-text">跳转定位</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9"><span class="toc-text">修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%80%89%E6%8B%A9"><span class="toc-text">选择</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%92%A4%E9%94%80"><span class="toc-text">撤销</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%8D%E5%88%B6"><span class="toc-text">复制</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B2%98%E8%B4%B4"><span class="toc-text">粘贴</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%AE%E6%94%B9-1"><span class="toc-text">修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%90%9C%E7%B4%A2"><span class="toc-text">搜索</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BF%BD%E7%95%A5%E5%A4%A7%E5%B0%8F%E5%86%99%E6%9F%A5%E6%89%BE"><span class="toc-text">忽略大小写查找</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9C%A8vim%E5%86%85%E6%89%A7%E8%A1%8C%E5%A4%96%E9%83%A8%E5%91%BD%E4%BB%A4"><span class="toc-text">在vim内执行外部命令</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BF%9D%E5%AD%98%E6%96%87%E4%BB%B6"><span class="toc-text">保存文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8F%90%E5%8F%96%E5%92%8C%E5%90%88%E5%B9%B6%E6%96%87%E4%BB%B6"><span class="toc-text">提取和合并文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%89%93%E5%BC%80%E6%96%B0%E7%9A%84%E4%B8%80%E8%A1%8C%E8%BE%93%E5%85%A5"><span class="toc-text">打开新的一行输入</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%91%BD%E4%BB%A4%E8%A1%A5%E5%85%A8"><span class="toc-text">命令补全</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#vimrc%E8%BF%9B%E9%98%B6%E9%85%8D%E7%BD%AE"><span class="toc-text">.vimrc进阶配置</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE"><span class="toc-text">基本配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%87%E4%BB%BD%E5%92%8C%E6%92%A4%E6%B6%88%E6%96%87%E4%BB%B6"><span class="toc-text">备份和撤消文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%BC%A0%E6%A0%87%E6%94%AF%E6%8C%81"><span class="toc-text">鼠标支持</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%B8%AD%E6%96%87%E6%94%AF%E6%8C%81"><span class="toc-text">中文支持</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E4%BD%93%E9%85%8D%E7%BD%AE"><span class="toc-text">字体配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%AA%E8%A6%81%E5%B1%8F%E5%B9%95%E8%83%BD%E6%BB%9A%E5%8A%A8%EF%BC%8C%E5%85%B3%E6%A0%87%E5%B0%B1%E6%97%A0%E6%B3%95%E7%A7%BB%E5%8A%A8%E5%88%B0%E4%B8%8A%E9%9D%A2%E7%9A%844%E8%A1%8C%E5%92%8C%E6%9C%80%E4%B8%8B%E9%9D%A24%E8%A1%8C"><span class="toc-text">只要屏幕能滚动，关标就无法移动到上面的4行和最下面4行</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#minpac%E5%AE%89%E8%A3%85"><span class="toc-text">minpac安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9C%80%E8%BF%91%E4%BD%BF%E7%94%A8%E7%9A%84%E6%96%87%E4%BB%B6"><span class="toc-text">最近使用的文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B7%B2%E7%BB%8F%E5%AD%98%E5%9C%A8%E4%BA%A4%E6%8D%A2%E6%96%87%E4%BB%B6"><span class="toc-text">已经存在交换文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E6%96%87%E4%BB%B6%E6%89%93%E5%BC%80%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="toc-text">多文件打开的方式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E7%AA%97%E5%8F%A3%E7%BC%96%E8%BE%91"><span class="toc-text">多窗口编辑</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%8C%E7%AA%97%E5%8F%A3%E6%AF%94%E8%BE%83"><span class="toc-text">双窗口比较</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%9A%E6%A0%87%E7%AD%BE%E9%A1%B5"><span class="toc-text">多标签页</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#NERDTree%E6%8F%92%E4%BB%B6"><span class="toc-text">NERDTree插件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%89%E8%A3%85"><span class="toc-text">安装</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8"><span class="toc-text">使用</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%EF%BC%9A%E5%AE%9E%E7%8E%B0%E6%96%87%E4%BB%B6%E5%86%85%E5%AE%B9%E7%9A%84%E6%90%9C%E7%B4%A2%E5%92%8C%E6%9B%BF%E6%8D%A2"><span class="toc-text">正则表达式：实现文件内容的搜索和替换</span></a></li></ol></li></ol>
    </div>
  </div>


            </div>
        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/2022/10/17/vim必会命令/">http://haohongbin.gitee.io/blog/2022/10/17/vim必会命令/</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
        
<nav id="article-nav">
  
    <a href="/blog/2022/09/27/Java%E5%B7%A5%E5%85%B7%E7%B1%BB%E5%92%8C%E6%96%B0%E8%AF%AD%E6%B3%95/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">older</strong>
      <div class="article-nav-title">
        
          Java工具类和新语法
        
      </div>
    </a>
  
  
    <a href="/blog/2022/11/01/TestNG%E5%9F%BA%E7%A1%80/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">newer</strong>
      <div class="article-nav-title">
        
          TestNG基础
        
      </div>
    </a>
  
</nav>

      
      
        








      
    </footer>
  </div>
</article>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-posts"></i> 最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2023/03/14/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E5%88%97%E8%A1%A8%E5%92%8C%E5%85%83%E7%BB%84/">(no title)</a>
          </li>
        
          <li>
            <a href="/blog/2023/03/09/Java%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95Mock%E7%A5%9E%E5%99%A8/">Java单元测试Mock神器</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/21/Pytest%E6%89%A7%E8%A1%8C%E7%94%A8%E4%BE%8B%E7%9A%84%E5%A4%9A%E7%A7%8D%E6%96%B9%E5%BC%8F/">Pytest执行用例的多种方式</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/20/SQL%E6%9F%A5%E8%AF%A2%E5%9C%BA%E6%99%AF/">SQL查询场景</a>
          </li>
        
          <li>
            <a href="/blog/2023/01/18/MySQL%E5%91%BD%E4%BB%A4%E6%89%8B%E5%86%8C/">MySQL命令手册</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签云</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/MySQL/" style="font-size: 15px;">MySQL</a> <a href="/blog/tags/%E5%88%86%E4%BA%AB/" style="font-size: 15px;">分享</a> <a href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" style="font-size: 10px;">单元测试</a> <a href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" style="font-size: 20px;">学习总结</a> <a href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 10px;">自动化</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-classify"></i> 分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF/">Java核心技术</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/vim/">vim</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%90%8E%E7%AB%AF/">后端</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95/">测试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95%E8%BF%9B%E9%98%B6/">测试进阶</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-archive"></i> 归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/">2023年</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/">2022年</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/MySQL/" rel="tag">MySQL</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%88%86%E4%BA%AB/" rel="tag">分享</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" rel="tag">单元测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" rel="tag">自动化</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


  
    

  
</aside>
        
      </div>
      <a id="totop" href="#top"></a>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      <p>
        <a href="/blog/sitemap.xml">网站地图</a>
        <span> | </span><a href="/blog/atom.xml">订阅本站</a>
        <span> | </span><a href="/blog/about/">联系博主</a>
      </p>
      
        <p>
          <i class="fa fa-visitors"></i>
          <i id="busuanzi_container_site_uv"><i id="busuanzi_value_site_uv"></i></i>
          ，
          <i class="fa fa-views"></i>
          <i id="busuanzi_container_site_pv"><i id="busuanzi_value_site_pv"></i></i>
        </p>
      
      <p>
        <span>Copyright &copy; 2023 奉孝.</span>
        <span>Theme by <a href="https://github.com/chaooo/hexo-theme-BlueLake/" target="_blank">BlueLake.</a></span>
        <span>Powered by <a href="https://hexo.io/" target="_blank">Hexo.</a></span>
      </p>
    </div>
  </div>
</footer>

    </div>
  </div>
  
<script src="/blog/js/jquery-3.4.1.min.js"></script>


<script src="/blog/js/search.json.js"></script>


  
<script src="/blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog/js/script.js"></script>






  
<script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  
    
<script src="/blog/localshare/js/social-share.js"></script>

    
<script src="/blog/localshare/js/qrcode.js"></script>

  
  



  

  

  

  

  

  

  

  
  





</body>
</html>